var mvs = require('../network/Matchvs');
var gameData = require('../network/gameData');
var playerData = require('../network/playerData');
function MatchvsEngine () {

}

MatchvsEngine.prototype.init = function () {
    var result = mvs.engine.init(mvs.response,gameData.init.channel,gameData.init.platform,
        gameData.init.gameID,gameData.init.appKey,gameData.init.verdion);
    return result;
};

MatchvsEngine.prototype.registerUser = function () {
    var result = mvs.engine.registerUser();
    return result;
};

MatchvsEngine.prototype.login = function (userID,token,deviceID) {
    var result = mvs.engine.login(userID,token,deviceID);
    return result;
};

MatchvsEngine.prototype.createRoom = function (roomMsg) {
    gameData.createRoomInfo.roomName = roomMsg.roomName;
    gameData.createRoomInfo.canWatch = roomMsg.canWatch;
    //createRoom(roomInfo,userProperty)   
    //roomInfo {roomName, maxPlayer, mode, canWatch, visibility, roomProperty}
    var result = mvs.engine.createRoom(gameData.createRoomInfo,playerData.presentPlayer.name);

    return result;
};

MatchvsEngine.prototype.getRoomList  = function () {
    var fliter = {
        maxPlayer: gameData.createRoomInfo.maxPlayer,
        mode: gameData.createRoomInfo.mode,
        canWatch: gameData.createRoomInfo.canWatch,
        roomProperty: gameData.createRoomInfo.roomProperty,
    }
    var result = mvs.engine.getRoomList(fliter);
    return result;
}

MatchvsEngine.prototype.getRoomListEx = function () {
    gameData.filter.mode = gameData.createRoomInfo.mode;
    var result = mvs.engine.getRoomListEx(gameData.filter); //参数不能写错
    
    return result;
}

MatchvsEngine.prototype.joinRoom = function (roomID,playerName) {
    var result = mvs.engine.joinRoom(roomID,playerName);
    if(result == 0){
        cc.director.loadScene("fight");
    }
    return result;
}

MatchvsEngine.prototype.joinRandomRoom = function () {
    var result = mvs.engine.joinRandomRoom(3, playerData.presentPlayer.name);
    return result;
}

MatchvsEngine.prototype.sendEvent = function (data) {
    var result = mvs.engine.sendEvent(data);
    return result;
}

MatchvsEngine.prototype.leaveRoom = function (cpProto) {
    var result = mvs.engine.leaveRoom(cpProto);
    return result;
}

// MatchvsEngine.prototype.sendEventEx = function (data, ID) {
//     var userid = new Array;
//     userid.push = ID;
//     console.log(userid);
//     var result = mvs.engine.sendEventEx(0,data,1 ,userid);
//     return result;
// }
module.exports = MatchvsEngine;